package com.iocup.keybastion.configuration;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xyjxust
 * @create 2022/3/8 15:44
 **/
@Setter
@Getter
public class DeviceProperties {

    private boolean enabled = true;

    private List<Device> devices = new ArrayList<>();

    @Setter
    @Getter
    public static class Device {
        /**
         * 客户端编码
         */
        private String code;
        /**
         * 客户端名称
         */
        private String name;
        /**
         * token校验时长：  单位秒，默认24小时
         */
        private int tokenValiditySeconds = 86400;
        /**
         * token刷新校验时长，单位秒，默认30天
         */
        private int refreshTokenValiditySeconds = 2592000;
    }

    public Device getDevice(String code){
        return this.devices.stream().filter(device -> device.code.equalsIgnoreCase(code))
                .findFirst().orElse(null);
    }

}
